package cn.tedu.mintmall.controller.fore;

import cn.tedu.mintmall.dto.AddressAddNewDTO;
import cn.tedu.mintmall.dto.AddressUpdateDTO;
import cn.tedu.mintmall.restful.JsonResult;
import cn.tedu.mintmall.service.IAddressService;
import cn.tedu.mintmall.vo.AddressVO;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/fore/address", produces = "application/json; charset=utf-8")
@Api(tags = "前台-地址管理")
public class AddressController {

    @Autowired
    private IAddressService addressService;

    @PostMapping("/add-new")
    @ApiOperation("新增地址")
    @ApiOperationSupport(order = 1)
    public JsonResult<Void> addNew(AddressAddNewDTO addressAddNewDTO){
        addressService.addAddress(addressAddNewDTO);
        return JsonResult.ok();
    }

    @GetMapping("/remove-by-user-id")
    @ApiOperation("删除地址")
    @ApiOperationSupport(order = 2)
    public JsonResult<Void> removeAddress(Long userId){
        addressService.removeAddress(userId);
        return JsonResult.ok();
    }

    @PostMapping("/update-by-contact-name")
    @ApiOperation("根据联系人修改地址")
    @ApiOperationSupport(order = 3)
    public JsonResult<Void> updateAddress(AddressUpdateDTO addressUpdateDTO){
        addressService.updateAddress(addressUpdateDTO);
        return JsonResult.ok();
    }

    @GetMapping("/select-by-contact-name")
    @ApiOperation("根据联系人查看地址")
    @ApiOperationSupport(order = 4)
    public JsonResult<AddressVO> removeAddress(
            @RequestParam(value = "contactName", required = true) String contactName){
        AddressVO addressVO = addressService.findAddressByContactName(contactName);
        return JsonResult.ok("为您查询到的地址信息!",addressVO);
    }

}
